import Vue from 'vue'
import Vuex from 'vuex'
import VueResource from 'vue-resource'

Vue.use(Vuex)
Vue.use(VueResource);
// const state = {
//   "newbi":"1",
//   "leftmenuShow":true,
//   "openid":"",
//   "headImgUrl":"http://s16.sinaimg.cn/orignal/49f161877ae588b03d39f",
//   "name":"葛琼",
//   "nickname":"大琼子",
//   "sex":"0",
//   "examTime":"2016-12-17",
//   "oneday":"20",
//   "province":"陕西",
//   "city":"宝鸡",
//   "country":"中国",
//   "regdate":"2017-01-05 03:51:12",
//   "xp":"27",
//   "memory":"43",
//   "notice":"1"
// }
//相当于一个计算属性
const getters = {
  stime:function(){
    var date = new Date();
    return date.getTime();
  }
}

const mutations={
  percentAdd (state) { //改变$store.state里的值
    state.percent++;
  },
  go (state,data){  //路由跳转的方法
    console.log(data);
    data[0].push({path:data[1]})
  }
}

var state,xmlhttp;
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
  if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
    console.log("请求成功!");
    console.log(xmlhttp.responseText);
    // state = xmlhttp.responseText;
    // state = eval('('+xmlhttp.responseText+')')
    state = JSON.parse(xmlhttp.responseText).data;
  }
  else{
    state = {serverIP:0}
  }
}
xmlhttp.open('GET','/api/users',false)
xmlhttp.send();
export default new Vuex.Store({
  state,
  getters,
  mutations
  // mounted(){
  //          this.$http.get('/api/seller').then(function(response){
  //         this.state = response;
  //      })
  // }
})
